<%-- 
    Document   : stdmaster_db
    Created on : Jan 10, 2013, 3:08:17 PM
    Author     : kk
--%>


<%@page contentType="text/html" pageEncoding="UTF-8"  import="java.sql.*, java.io.*, org.json.simple.*" %>
<!DOCTYPE html>
<html>
    <head>
        <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
        <title>JSP Page</title>
    </head>
    <body>
         <%
         String regid=new String("a123");
         String photopath=new String("abcd");
        try{
            String grno=request.getParameter("stud-gr-no");
            String firstname=request.getParameter("stud-first-name");
            String middlename=request.getParameter("stud-middle-name");
            String lastname=request.getParameter("stud-last-name");
            String mothername=request.getParameter("stud-mother-name");
            String cast=request.getParameter("stud-cast");
            String castcategory=request.getParameter("stud-cast-category");
            String birthdate=request.getParameter("stud-birth-date");
            String city=request.getParameter("stud-birth-city");
            String state=request.getParameter("stud-birth-state");
            String country=request.getParameter("stud-birth-country");
            String bloodgroup=request.getParameter("stud-bloodgroup");
            String presentaddress=request.getParameter("stud-present-address");
            String permanentaddress=request.getParameter("stud-permanent-address");
            String permanentcity=request.getParameter("stud-permanent-city");
            String permanentstate=request.getParameter("stud-permanent-state");
            String permanentcountry=request.getParameter("stud-permanent-country");
            String permanentpincode=request.getParameter("stud-permanent-pincode");
            String nationality=request.getParameter("stud-nationality");
            String religion=request.getParameter("stud-religion");
            String studentcontactno=request.getParameter("stud-contact-no");
            String parentscontactno=request.getParameter("stud-parents-no");
            String alternativecontactno=request.getParameter("stud-alter-no");
            String admissiondate=request.getParameter("stud-admission-date");
            String admissionstd=request.getParameter("stud-admission-std");
            String division=request.getParameter("stud-std-division");
            String remark=request.getParameter("stud-admission-remark");
            
            JSONObject obj=new JSONObject();
            
            obj.put("firstname", firstname);
            obj.put("middlename", middlename);
            obj.put("lastname", lastname);
            obj.put("mothername", mothername);
            obj.put("cast", cast);
            obj.put("castcategory", castcategory);
            obj.put("birthdate", birthdate);
            
            
            JSONObject birthplace=new JSONObject();
                birthplace.put("city", city);
                birthplace.put("state", state);
                birthplace.put("country", country);
            obj.put("birthplace", birthplace);
            
            obj.put("bloodgroup", bloodgroup);
            
            JSONObject address=new JSONObject();
                address.put("presentaddress", presentaddress);
                    JSONObject permanent=new JSONObject();
                        permanent.put("permanentaddress", permanentaddress);
                        permanent.put("city", permanentcity);
                        permanent.put("state", permanentstate);
                        permanent.put("country", permanentcountry);
                        permanent.put("pincode", permanentpincode);
                address.put("permanentaddress", permanent);
            obj.put("address", address);
            
            obj.put("nationality", nationality);
            obj.put("religion", religion);
            
            JSONObject contactno=new JSONObject();
                contactno.put("student", studentcontactno);
                contactno.put("parents", parentscontactno);
                contactno.put("alternative", alternativecontactno);
            obj.put("contactno", contactno);
            
            obj.put("admissiondate", admissiondate);
            obj.put("admissionstd", admissionstd);
            obj.put("division", division);
            obj.put("remark", remark);
            
            Class.forName("com.mysql.jdbc.Driver");
            Connection con=DriverManager.getConnection("jdbc:mysql://localhost:3306/shms", "root", "");
            String query="insert into student_master (gr_no, reg_id, photo, student_detail) values ('"+grno+"','"+regid+"','"+photopath+"','"+obj.toJSONString()+"') ";
            Statement stmt=con.createStatement();
            int rst=stmt.executeUpdate(query);
            
            if(rst == 1)
            {
            application.setAttribute("msg","true");
            }
            else
            {
            application.setAttribute("msg","false");
            }
            
            response.sendRedirect("stdmaster.jsp");
               
        }
        catch(Exception e) {}
        %>
    </body>
</html>
